package cn.kgc.libraryapplication.service;

import cn.kgc.librarycommon.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class UserServiceImpl implements UserService{

    @Autowired
    private RestTemplate restTemplate;

    @Value("${user.rest.url}")
    private String userUrl;

    @Override
    public Integer isRepeat(String userName) {
        return restTemplate.getForObject(userUrl+"/isRepeat?userName="+userName, Integer.class);
    }

    @Override
    public Integer addUser(User user) {
        return restTemplate.postForObject(userUrl+"/addUser", user, Integer.class);
    }

    @Override
    public User login(String username) {
        return restTemplate.getForObject(userUrl+"/login?username="+username,User.class);
    }
}
